<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


class AdvertisementModel extends Model
{


	//缓存广告
	public function cacheAdvertisements()
    {
        $time = time();
        $results = array();
        $prefix = $this->tablePrefix;
        $where = " status=1 AND (start_time=0 OR start_time<{$time}) AND (expire_time=0 OR expire_time>{$time})";
    	$sql  = " SELECT A.html_code, L.identifier, L.template FROM {$prefix}advertisement A ";
    	$sql .= " LEFT JOIN {$prefix}ad_location L USING(location_id) ";
    	$sql .= " WHERE {$where} ";

    	$ads = $this->query($sql);
    	if (!empty($ads))
    	{
    		foreach ($ads as $value)
    		{
    		    $results[$value['identifier']]['template'] = $value['template'];
    			$results[$value['identifier']]['html_code'][] = $value['html_code'];
    		}
    	}
    	F('cache_advertisements', $results);
	}

}


/* End of file AdvertisementModel.class.php */
/* Location: ./App/Lib/Model/AdvertisementModel.class.php */